package com.RMP
{
    import flash.display.*;
    import flash.events.*;
    import flash.net.*;
    import flash.text.*;
    import com.greensock.*;

    public class BookmarksPageThumbnail extends Sprite
    {
        var loader:Loader;
        public var icons:BookmarksIcons;
        var imagePath:String;
        var fadeSpeed:Number;
        public var dbId:Number;
        public var btnOver:Sprite;
        var image:Bitmap;
        public var idNum:Number;
        public var btn:Sprite;
        var frame:Frame;
        var myRoot:MovieClip;
        var styler:StyleSheet;
        var myText:String;
        public var field:BigFieldNarrow;
        var myBorder:String;

        public function BookmarksPageThumbnail(param1:MovieClip, param2:Number, param3:String, param4:Number, param5:Number, param6:String, param7:String) : void
        {
            myRoot = param1;
            fadeSpeed = param2;
            myText = param3;
            idNum = param4;
            dbId = param5;
            imagePath = param6;
            trace("imagePath " + imagePath);
            myBorder = param7;
            buildStyles();
            buildImage();
            myRoot.stage.addEventListener(Event.RESIZE, onResizer);
            doResize();
            return;
        }

        function buildStyles() : void
        {
            var _loc_1:* = undefined;
            var _loc_2:* = undefined;
            var _loc_3:Object = null;
            var _loc_4:Object = null;
            var _loc_5:Object = null;
            var _loc_6:Object = null;
            _loc_1 = new HelveticaLightEmbed().fontName;
            _loc_2 = new HelveticaBoldEmbed().fontName;
            styler = new StyleSheet();
            _loc_3 = new Object();
            _loc_3.color = myRoot.coldColorHTML;
            _loc_3.fontFamily = _loc_1;
            _loc_3.leading = -4;
            _loc_4 = new Object();
            _loc_4.color = myRoot.coldColorHTML;
            _loc_4.textDecoration = "none";
            _loc_5 = new Object();
            _loc_5.color = myRoot.hotColorHTML;
            _loc_5.textDecoration = "none";
            _loc_6 = new Object();
            _loc_6.color = myRoot.coldColorHTML;
            _loc_6.fontFamily = _loc_2;
            styler.setStyle("p", _loc_3);
            styler.setStyle("a:link", _loc_4);
            styler.setStyle("a:hover", _loc_5);
            styler.setStyle(".mybold", _loc_6);
            return;
        }

        public function fadeOutShell() : void
        {
            TweenMax.to(this, fadeSpeed, {alpha:0, overwrite:true, onComplete:function ()
            {
                visible = false;
                return;
            }
            });
            return;
        }

        public function rollOverEvent() : void
        {
            if (myRoot.localPagesXML.page.length() == 1)
            {
                icons.btnL.visible = false;
                icons.btnR.visible = false;
            }
            if (icons != null)
            {
                icons.alpha = 1;
            }
            TweenMax.to(field, fadeSpeed, {tint:16724736, overwrite:true});
            TweenMax.to(btnOver, fadeSpeed, {alpha:0.5, overwrite:true});
            return;
        }

        function doResize() : void
        {
            btn.width = Math.round(4 * myRoot.unitW + 3 * myRoot.gutterW);
            btnOver.width = Math.round(2 * myRoot.unitW + myRoot.gutterW);
            var _loc_1:* = 2 * myRoot.unitH + myRoot.gutterH;
            btnOver.height = 2 * myRoot.unitH + myRoot.gutterH;
            btn.height = _loc_1;
            if (image != null)
            {
                image.width = Math.round(2 * myRoot.unitW + myRoot.gutterW);
                image.scaleY = image.scaleX;
                image.height = Math.round(image.height);
            }
            var _loc_1:* = myRoot.unitW / 75;
            field.scaleY = myRoot.unitW / 75;
            field.scaleX = _loc_1;
            field.x = Math.round(-3 * field.scaleX + btnOver.width + myRoot.gutterW);
            field.y = Math.round(6 * field.scaleX);
            if (frame != null)
            {
                frame.resizeFrame(image.width, image.height);
            }
            if (icons != null)
            {
                icons.x = 0;
                icons.y = 0;
            }
            return;
        }

        function onResizer(event:Event)
        {
            doResize();
            return;
        }

        public function rollOutEvent() : void
        {
            if (icons != null)
            {
                icons.alpha = 0;
            }
            TweenMax.to(field, fadeSpeed * 3, {tint:7829367, overwrite:true});
            TweenMax.to(btnOver, fadeSpeed * 3, {alpha:0, overwrite:true});
            return;
        }

        function addEmptyImage() : void
        {
            addChild(btnOver);
            icons = new BookmarksIcons(myRoot, fadeSpeed);
            icons.alpha = 0;
            addChild(icons);
            doResize();
            return;
        }

        function buildImage() : void
        {
            var _loc_1:* = undefined;
            _loc_1 = new TextFormat();
            _loc_1.font = new HelveticaLightEmbed().fontName;
            _loc_1.size = 14;
            _loc_1.letterSpacing = 0;
            _loc_1.leading = -4;
            _loc_1.leftMargin = 0;
            _loc_1.rightMargin = 0;
            _loc_1.color = myRoot.coldColor;
            btn = new Sprite();
            btn.useHandCursor = true;
            btn.mouseEnabled = true;
            btn.buttonMode = true;
            btn.mouseChildren = false;
            btn.graphics.beginFill(16777215, 0);
            btn.graphics.drawRect(0, 0, 1, 1);
            btn.graphics.endFill();
            btnOver = new Sprite();
            btnOver.useHandCursor = false;
            btnOver.mouseEnabled = false;
            btnOver.buttonMode = false;
            btnOver.mouseChildren = true;
            btnOver.graphics.beginFill(16777215, 1);
            btnOver.graphics.drawRect(0, 0, 1, 1);
            btnOver.graphics.endFill();
            btnOver.alpha = 0;
            field = new BigFieldNarrow();
            field.name = "field";
            field.field.width = 159;
            field.field.autoSize = "left";
            field.field.antiAliasType = AntiAliasType.ADVANCED;
            field.field.gridFitType = GridFitType.PIXEL;
            field.field.selectable = false;
            field.field.embedFonts = true;
            field.field.multiline = true;
            field.field.wordWrap = true;
            field.field.styleSheet = styler;
            field.field.htmlText = "<p>" + myText + "</p>";
            field.field.y = -12;
            addChild(field);
            addChild(btn);
            addChild(btnOver);
            if (imagePath != "")
            {
                loader = new Loader();
                loader.load(new URLRequest(myRoot.path + imagePath));
                loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoadComplete);
            }
            else
            {
                addEmptyImage();
            }
            return;
        }

        function onLoadComplete(event:Event) : void
        {
            var event:* = event;
            image = Bitmap(loader.content);
            doResize();
            image.alpha = 0;
            addChild(image);
            if (myBorder == "1")
            {
                frame = new Frame();
                frame.alpha = 0;
                addChild(frame);
                frame.resizeFrame(image.width, image.height);
                TweenMax.to(frame, fadeSpeed, {alpha:1, overwrite:true});
            }
            addChild(btnOver);
            icons = new BookmarksIcons(myRoot, fadeSpeed);
            icons.alpha = 0;
            addChild(icons);
            doResize();
            TweenMax.to(image, fadeSpeed, {alpha:1, overwrite:true, onComplete:function ()
            {
                image.smoothing = true;
                return;
            }
            });
            return;
        }

        public function fadeInShell() : void
        {
            visible = true;
            TweenMax.to(this, fadeSpeed, {alpha:1, delay:fadeSpeed, overwrite:true});
            return;
        }

    }
}
